$(document).ready(function(){
    function show_resume(item){
        $('#name').text(item['personal_info']['name']);
        $('#sex').text(item['personal_info']['sex']);
        $('#age').text(item['personal_info']['age']);
        $('#exp').text(item['personal_info']['exp']);
        $('#edu').text(item['personal_info']['edu']);
        $('#address').text('现居住  :  ' + item['personal_info']['address']);
        $('#platform').text('所在平台  :  ' + item['platform']);
        $('#update_time').text('最近一次更新  :  ' + item['update_time']);
        $('.head-pic img').attr('src',item['head_pic']);
        $('#wanted_job').text(item['wanted_job']['title']);
        $('#wanted_city').text(item['wanted_job']['location']);
        $('#current_state').text(item['wanted_job']['current']);
        $('#wanted_industry').text(item['wanted_job']['industry']);
        $('#wanted_salary').text(item['wanted_job']['salary']);

        if(item['edu_experience'].length){
            var htmlstr = '';

            for(var i = 0;i < item['edu_experience'].length;i++){
                htmlstr += '<div style = "margin-top:6px;">';
                htmlstr += '<span style = "margin-left:20px;">' + item['edu_experience'][i]['time'] + '</span>';
                htmlstr += '<span style = "margin-left:20px;">' + item['edu_experience'][i]['school'] + '</span>';
                htmlstr += '<span style = "margin-left:20px;">' + item['edu_experience'][i]['major'] + '</span>';
                htmlstr += '<span style = "margin-left:20px;">' + item['edu_experience'][i]['level'] + '</span>';
                htmlstr += '</div>';
            }

            $('#education-list').html(htmlstr);
        }else{
            $('#education-list-container').hide();
        }

        if(item['work_experience'].length){
            var htmlstr = '';

            for(var i = 0;i < item['work_experience'].length;i++){
                htmlstr += '<div class = "work-exp-item"><div>';
                htmlstr += '<b style = "margin-left:20px;">' + item['work_experience'][i]['time'] + '</b>';
                htmlstr += '<b style = "margin-left:30px;">' + item['work_experience'][i]['company'] + ' </b>';
                htmlstr += '<b style = "float:right;margin-right:20px;">' + item['work_experience'][i]['title'] + '</b></div>';
                htmlstr += '<section style = "margin:20px;">';
                htmlstr += item['work_experience'][i]['describe'];
                htmlstr += '</section></div>';
            }

            $('#wordk-exp-list').html(htmlstr);
        }else{
            $('#wordk-exp-list-container').hide();
        }

        if(item['proj_experience'].length){
            var htmlstr = '';

            for(var i = 0;i < item['proj_experience'].length;i++){
                htmlstr += '<div class = "proj-exp-item"><div>';
                htmlstr += '<b style = "margin-left:20px;">' + item['proj_experience'][i]['time'] + '</b>';
                htmlstr += '<b style = "margin-left:30px;">' + item['proj_experience'][i]['title'] + '</b>';
                htmlstr += '<section style = "margin-left:20px;margin-right:20px;margin-top:20px;">';
                htmlstr += item['proj_experience'][i]['responsibility'];
                htmlstr += '</section><section style = "margin:20px;">';
                htmlstr += item['proj_experience'][i]['describe'];
                htmlstr += '</section></div>';
            }

            $('#proj-exp-list').html(htmlstr);
        }else{
            $('#proj-exp-list-container').hide();
        }

        $('#self_introduce').text(item['self_introduce']);
    }

//    var resume = null;

    $.ajax({
        'url':'/resume_info.do',
        'data':{
            'id':window.location.search.match(/id=(.+)/)[1]
        },
        'success':function(resp){
            if(resp.success){
                resume = resp.data;
                show_resume(resp.data);
            }else{
                alert(resp.msg);
            }
        }
    });

    // 获取联系方式
//    $('#get_contact_info').click(function(){
//        $.ajax({
//            'url':'/add_contact.do',
//            'data':{
//                'id':window.location.dig.match(/id=(.+)/)[1]
//            },
//            'success':function(resp){
//                if(resp.success){
//                    alert('正在为您获取联系方式，请您稍后在联系方式板块中查看!')
//                }else{
//                    alert(resp.msg);
//                }
//            }
//        });
//    });

    // 获取简历链接
    $('#get_resume_link').click(function(){
        $('#get_resume_link').text('正在获取，请稍等...');
//        $.ajax({
//            'url':'/get_contact.do',
//            'data':{
//                'id':window.location.dig.match(/id=(.+)/)[1]
//            },
//            'success':function(resp){
//                if(resp.success){
//                    if(resp.data.action == 'code'){
//                        $('#geetest_panel').removeClass('hidden');
//                        $('#geetest_item_wrap img').attr('src',resp.data.code_pic_src);
//                    }
//
////                    if(resp.data && resp.data.resume_url){
////                        $('#contact-info-container').removeClass('hidden');
////                        $('#contact-info-container a').text(resp.data.resume_url).attr('href',resp.data.resume_url);
////                        $('#get_resume_link').text('获取简历链接');
////                    }
//                }
//            }
//        })
    });

    var positions = [];

    $('#geetest_item_wrap').click(function(e){
        $('#geetest_item_wrap').append('<span class = "pointer" style = "left:' + (e.offsetX - 15) + 'px;top:' + (e.offsetY - 15) + 'px;">1</span>');

        positions.push({
            'offsetX':e.offsetX,
            'offsetY':e.offsetY
        });
    });

    $('#geetest_item_wrap .confirm').click(function(e){
        e.stopPropagation();

        $.ajax({
            'url':'/code_by_user.do',
            'data':{
                'positions':JSON.stringify(positions)
            },
            'success':function(resp){

            }
        })
    });
});